package com.code.complex;

/**
 * 常见的时间复杂度
 *  O(1) < O(log(n)) < O(n) < O(nlog(n)) < O(n^2)
 */
public class NormalTimeComplex {

  /**
   *  O(1) : 常数级别的时间复杂的
   */
  public static void timeComplex01() {

    System.out.println("11");
    int a = 10;
  }
  /**
   * O(log(n))
   */
  public static void timeComplex02(int n){

    if(n <= 0){

      return;
    }

    int index = 0;

    while (n > 0){

      index++;
      n = n / 2;
    }

    System.out.println(index);
  }

  /**
   * O(n)
   */
  public static void timeComplex03(int n){

    int sum = 0;
    for (int i = 0; i < n; i++) {

      sum += i;
    }

    System.out.println(sum);
  }

  /**
   *
   * O(n*log(n))
   */
  public static void timeComplex04(int n){

    int sum = 0;
    for (int i = 1; i <= n ; i+=i) {

      sum++;
      for (int j = i; j < n ; j++) {

//         sum += j;
      }
    }

    System.out.println(sum);
  }

  /**
   *
   * O(n^2)
   */
  public static void timeComplex05(int n){

    for (int i = 0; i < n ; i++) {
      for (int j = 0; j < n ; j++) {

      }
    }
  }


  public static void main(String[] args) {

//    timeComplex01();
//    timeComplex02(100);
    timeComplex04(100);
  }


}
